package cn.edu.njtc.controller;

import cn.edu.njtc.common.R;
import cn.edu.njtc.entity.pojo.PatientAttackRecord;
import cn.edu.njtc.entity.vo.PatientAttackRecordVo;
import cn.edu.njtc.service.PatientAttackRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Tag(name = "病人犯病记录管理接口")
@RestController
@RequestMapping("/patient-attack")
public class PatientAttackRecordController {

    @Autowired
    private PatientAttackRecordService recordService;
    @Operation(summary = "根据用户ID获取犯病记录")
    @GetMapping("/user/{userId}")
    public R<List<PatientAttackRecordVo>> getRecordsByUserId(@PathVariable Integer userId) {
        List<PatientAttackRecordVo> records = recordService.getRecordsByUserId(userId);
        return R.ok(records);
    }
    @Operation(summary = "根据记录ID获取犯病记录")
    @GetMapping("/{recordId}")
    public R<PatientAttackRecordVo> getRecordById(@PathVariable Integer recordId) {
        PatientAttackRecordVo record = recordService.getRecordById(recordId);
        if (record == null) {
            return R.failed("记录不存在或已被删除");
        }
        return R.ok(record);
    }
    @Operation(summary = "添加犯病记录")
    @PostMapping
    public R<?> addRecord(@RequestBody PatientAttackRecord record) {
        boolean success = recordService.addRecord(record);
        return success ? R.ok("添加成功") : R.failed("添加失败");
    }
    @Operation(summary = "更新犯病记录")
    @PutMapping
    public R<?> updateRecord(@RequestBody PatientAttackRecord record) {
        boolean success = recordService.updateRecord(record);
        return success ? R.ok("更新成功") : R.failed("更新失败");
    }
    @Operation(summary = "删除犯病记录")
    @DeleteMapping("/{recordId}")
    public R<?> deleteRecord(@PathVariable Integer recordId) {
        boolean success = recordService.deleteRecord(recordId);
        return success ? R.ok("删除成功") : R.failed("删除失败");
    }
}